package com.java.demo.java;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;

import java.text.SimpleDateFormat;
import java.util.Date;

@Data
public class WxOrderVO {

    public static void main(String[] args) {
        String json = "{\"amount\":{\"currency\":\"CNY\",\"payer_currency\":\"CNY\",\"payer_total\":1,\"total\":1},\"appid\":\"wxdace645e0bc2cXXX\",\"attach\":\"\",\"bank_type\":\"OTHERS\",\"mchid\":\"1900006XXX\",\"out_trade_no\":\"44_2126281063_5504\",\"payer\":{\"openid\":\"o4GgauJP_mgWEWictzA15WT15XXX\"},\"promotion_detail\":[],\"success_time\":\"2021-03-22T10:29:05+08:00\",\"trade_state\":\"SUCCESS\",\"trade_state_desc\":\"支付成功\",\"trade_type\":\"JSAPI\",\"transaction_id\":\"4200000891202103228088184743\"}";
        WxOrderVO wxOrderVO = JSON.parseObject(json, WxOrderVO.class);
        System.out.println(JSON.toJSONString(wxOrderVO));
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(format.format(wxOrderVO.getSuccessTime()));
    }

    @JSONField(name = "amount")
    private Amount amount;

    @JSONField(name = "bank_type")
    private String bankType;

    @JSONField(name = "out_trade_no")
    private String outTradeNo;

    @JSONField(name = "payer")
    private Payer payer;

    @JSONField(name = "success_time")
    private Date successTime;

    @JSONField(name = "trade_state")
    private String tradeState;

    @JSONField(name = "trade_state_desc")
    private String tradeStateDesc;

    @JSONField(name = "trade_type")
    private String tradeType;

    @JSONField(name = "transaction_id")
    private String transactionId;

    @Data
    public static class Amount {

        @JSONField(name = "payer_total")
        private int payerTotal;

        @JSONField(name = "total")
        private int total;
    }

    @Data
    public static class Payer {

        @JSONField(name = "openid")
        private String openId;
    }
}